package com.zst.bluetooth.task;

import com.zst.bluetooth.utils.BlueException;
import com.zst.bluetooth.utils.BlueToothUtils;
import com.zst.bluetooth.utils.TaskInfo;

/**
 * Created by zhang on 2016/3/19 0019.
 */
public class ConnectTask extends Thread {
    private TaskInfo info;
    private String msg;

    public ConnectTask(String msg) {
        this.msg = msg;
    }

    @Override
    public void run() {
        try {
            //发送消息
            BlueToothUtils.sendMsg(msg);
            info.onFinish("success");
        } catch (BlueException e) {
            //发送失败
            if (null != info)
                info.onFinish(e.getMessage());
        }
    }

    @Override
    public synchronized void start() {
        if (null != info)
            info.onPre();
        super.start();
    }

    public void setTaskInfo(TaskInfo info) {
        this.info = info;
    }
}
